/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InitialFrame.java
 *
 * Created on Jun 20, 2009, 8:33:53 PM
 */

package ces31.ChineseDicesClient.IU;

import ces31.ChineseDicesClient.SO_SistemaCliente;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;

/**
 *
 * @author Douglas
 */
public class IU_Inicial extends javax.swing.JFrame {

    /** Creates new form InitialFrame */
    public IU_Inicial() {
        initComponents();
    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        textoTituloJogo = new javax.swing.JLabel();
        imagemDados = new javax.swing.JLabel();
        textoVersao = new javax.swing.JLabel();
        textoNomeUsuario = new javax.swing.JLabel();
        campoNomeJogador = new javax.swing.JTextField();
        botaoSair = new javax.swing.JButton();
        botaoJogar = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JSeparator();
        textoManualUsuario = new javax.swing.JLabel();
        botaoManualUsuario = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        textoTituloJogo.setFont(new java.awt.Font("Arial", 1, 24));
        textoTituloJogo.setText("Dados Chineses");
        textoTituloJogo.setName("textoTituloJogo"); // NOI18N

        imagemDados.setIcon(new javax.swing.ImageIcon(getClass().getResource("/ces31/ChineseDicesClient/IU/small_dices.jpg"))); // NOI18N
        imagemDados.setName("imagemDados"); // NOI18N

        textoVersao.setText("Versão 1.0");
        textoVersao.setName("textoVersao"); // NOI18N

        textoNomeUsuario.setText("Nome de usuário");
        textoNomeUsuario.setName("textoNomeUsuario"); // NOI18N

        campoNomeJogador.setName("campoNomeJogador"); // NOI18N

        botaoSair.setText("Sair");
        botaoSair.setName("quitButton"); // NOI18N
        botaoSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sair(evt);
            }
        });

        botaoJogar.setText("Jogar");
        botaoJogar.setName("botaoJogar"); // NOI18N
        botaoJogar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                adicionarASalaDeEspera(evt);
            }
        });

        jSeparator1.setName("jSeparator1"); // NOI18N

        textoManualUsuario.setText("Para aprender as regras do jogo, acesse o Manual do Usuário.");
        textoManualUsuario.setName("textoManualUsuario"); // NOI18N

        botaoManualUsuario.setText("Manual do Usuário");
        botaoManualUsuario.setName("botaoManualUsuario"); // NOI18N
        botaoManualUsuario.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                apresentarManual(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(imagemDados)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(textoTituloJogo)
                                    .addGap(16, 16, 16))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 146, Short.MAX_VALUE)
                                    .addComponent(textoVersao)
                                    .addContainerGap())))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(textoNomeUsuario)
                            .addContainerGap(238, Short.MAX_VALUE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(campoNomeJogador, javax.swing.GroupLayout.PREFERRED_SIZE, 266, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addContainerGap(52, Short.MAX_VALUE))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addComponent(botaoSair)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(botaoJogar)
                            .addGap(29, 29, 29))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 310, Short.MAX_VALUE)
                            .addGap(8, 8, 8))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(textoManualUsuario)
                            .addContainerGap(18, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(botaoManualUsuario)
                        .addGap(27, 27, 27))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(textoVersao)
                        .addGap(5, 5, 5)
                        .addComponent(textoTituloJogo))
                    .addComponent(imagemDados))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textoNomeUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(campoNomeJogador, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botaoJogar)
                    .addComponent(botaoSair))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textoManualUsuario)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(botaoManualUsuario)
                .addGap(7, 7, 7))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents


/**
 * Caso de Uso: Adicionar na sala de espera
 * @param name
 */
    private void adicionarASalaDeEspera(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_adicionarASalaDeEspera
        //apertou o botao para conectar o cliente
        campoNomeJogador.setEditable(false);
        botaoJogar.setEnabled(false);
        String mensagem = SO_SistemaCliente.getSalaDeEspera().conectarseAoServidor(coletarNomeJogador());
        if(mensagem != null){
            this.apresentarMensagem(mensagem);
        }
        this.setVisible(false);
    }//GEN-LAST:event_adicionarASalaDeEspera

    private String coletarNomeJogador(){
        return campoNomeJogador.getText();
    }

    /**
 * Caso de Uso: Encerrar Cliente
 * @param evt
 */
    private void sair(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sair
        //apertou o botao de sair (encerra a aplicacao)
        this.setVisible(false);
        
        try {
            SO_SistemaCliente.encerrarCliente();
        } catch (Throwable ex) {
            Logger.getLogger(IU_Inicial.class.getName()).log(Level.SEVERE, null, ex);
        }
}//GEN-LAST:event_sair
/**
 * Caso de Uso: Consultar Manual
 * @param evt
 */
    private void apresentarManual(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_apresentarManual
        botaoJogar.setEnabled(false);
        IU_Manual userguide = new IU_Manual(this);
        userguide.setVisible(true);
}//GEN-LAST:event_apresentarManual



    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton botaoJogar;
    private javax.swing.JButton botaoManualUsuario;
    private javax.swing.JButton botaoSair;
    private javax.swing.JTextField campoNomeJogador;
    private javax.swing.JLabel imagemDados;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel textoManualUsuario;
    private javax.swing.JLabel textoNomeUsuario;
    private javax.swing.JLabel textoTituloJogo;
    private javax.swing.JLabel textoVersao;
    // End of variables declaration//GEN-END:variables

    public javax.swing.JFrame apresentarMensagem(String mensagem) {
        if(mensagem.equals("Espera Adversario")){
            IU_ResultadoInstance = new IU_Espera();
            return IU_ResultadoInstance;
        }
        else{
            IU_ResultadoInstance = new IU_Mensagem(mensagem);
        }
        return null;
    }

    private javax.swing.JFrame IU_ResultadoInstance;

    public JButton getBotaoJogar() {
        return botaoJogar;
    }

    
}
